package LeetCode;

import java.util.HashMap;

/**
 * @Author：DijaH
 * @Date：2022/12/17 7:54 下午
 * @Version：1.0.0
 * @Description：
 */
public class lengthOfLongestSubstring {

    public static int getMaxLengthSubstring(String s){
        if(s.length() == 0){
            return 0;
        }
        HashMap<Character,Integer> map = new HashMap<>();
        int max = 0;
        int left = 0;
        for(int i = 0; i<s.length();i++){
            if(map.containsKey(s.charAt(i))){
                left = Math.max(left,map.get(s.charAt(i)) + 1);
            }
            map.put(s.charAt(i),i);
            max = Math.max(max,i-left+1);
        }
        return max;
    }

    public static void main(String[] args) {
        String a = "abcabccdd";
        int maxLengthSubstring = getMaxLengthSubstring(a);
        System.out.println(maxLengthSubstring);
    }
}
